﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Markup;
using System.Collections;
using System.Collections.Specialized;

namespace SDF.Primitives
{
    public class LogicalChildrenCollection<T>: SmartDataObjectCollection<T> where T:DependencyObject, ISmartDataObject
    {
        #region Constructor

        public LogicalChildrenCollection(DependencyObject container)
        {
            if (container == null)
                throw new ArgumentNullException("container");
            
            Container = container;
        }

        #endregion

        #region Properties

        public DependencyObject Container { get; private set; }

        #endregion

        #region Methods

        protected override void InsertItem(int index, T item)
        {
            SmartLogicalTreeHelper.AddChild(Container, item);
            base.InsertItem(index, item);
        }

        protected override void RemoveItem(int index)
        {
            if ((index < 0) || (index >= this.Count))
                throw new ArgumentOutOfRangeException("index");

            T item = this[index];
            base.RemoveItem(index);
            SmartLogicalTreeHelper.RemoveChild(Container, item);
        }

        #endregion


    }
}
